﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.AspNetCore.Mvc.Authorization;
using Abp.Auditing;
using Abp.Web.Models;
using FwProject.Com;
using FwProject.Com.Dto;
using FwProject.Controllers;
using FwProject.ShoppingMall.Com;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;

namespace FwProject.Web.Shop.Controllers
{
    [AbpMvcAuthorize]
    public class SettlementController : FwProjectControllerBase
    {
        private readonly ISettlementSupplierAppService _settlementSupplierAppService;
        private readonly IShopOrderDetailsAppService _shopOrderDetailsAppService;
        private readonly IShopSupplierAppService _shopSupplierAppService;
        private readonly IHostingEnvironment _env;

        public SettlementController(ISettlementSupplierAppService settlementSupplierAppService, IShopOrderDetailsAppService shopOrderDetailsAppService,
            IShopSupplierAppService shopSupplierAppService, IHostingEnvironment env)
        {
            _settlementSupplierAppService = settlementSupplierAppService;
            _shopOrderDetailsAppService = shopOrderDetailsAppService;
            _shopSupplierAppService = shopSupplierAppService;
            _env = env;
        }
        /// <summary>
        /// 结算单
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> Index()
        {
            var list = await _shopSupplierAppService.GetListAsync();
            ViewBag.Supplier = list;
            return View();
        }
        /// <summary>
        /// 获取结算单数据
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        [DisableAuditing]
        [WrapResult(false, false)]
        public async Task<IActionResult> GetSupplierSettmentData(int page,int limit,string Supplier,string SettlementTime,string ExamineStatus)
        {
            var model = await  _settlementSupplierAppService.GetSupplierSettlementAsync(page,limit,Supplier,SettlementTime, ExamineStatus);
            return Json(model);
        }
        /// <summary>
        /// 查看结算订单明细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<IActionResult> OrderDetails(Guid id,ExamineStatus examineStatus)
        {

            ViewBag.Id = id;
            ViewBag.ExamineStatus = examineStatus;
            var list = await _shopOrderDetailsAppService.GetOrderDetailsBySettlementIdAsync(id);
            return View(list);
        }

        public async Task<IActionResult> Examine(Guid id)
        {
            await _settlementSupplierAppService.EditExamineStatus(id);
            return Json(1);
        }
        /// <summary>
        /// 结算单导出
        /// </summary>
        /// <param name="Supplier"></param>
        /// <param name="SettlementTime"></param>
        /// <returns></returns>
        public async Task<IActionResult> ExportSettlementData(string Supplier, string SettlementTime)
        {
            var data = await _settlementSupplierAppService.GetExportSupplierSettlementAsync(Supplier, SettlementTime);

            return DoExcel<SupplierSettlementOutput>(data, _env);
        }
    }
}